function calculateDateDifference(date1: Date, date2: Date) {
  if (date1 >= date2) {
    return "已结束";
  }
  date2 = new Date(date2)
  // 创建两个新的 Date 对象
  const d1 = new Date(date1);
  const d2 = new Date(date2);

  // 忽略时分秒，设置为零
  d1.setHours(0, 0, 0, 0);
  d2.setHours(0, 0, 0, 0);

  // 计算毫秒差距
  const timeDiff = d2.getTime() - d1.getTime();

  // 将毫秒差距转换为天数
  const daysDiff = Math.floor(timeDiff / (24 * 60 * 60 * 1000));

  return daysDiff + "天";
}

Component({
  properties: {
    avatar: {
      type: String,
      value: null,
    },
    endDate: {
      type: Number,
      value: new Date().getTime(),
    },
    publisher: {
      type: String,
      value: "未知"
    }
  },
  data: {
    remainingDays: "未知",
  },
  observers: {
    "endDate": function (date: Date) {
      this.setData({
        remainingDays: calculateDateDifference(Date.now(), this.data.endDate)
      })
    }
  },
  methods: {}
});
